from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        CREATE TABLE IF NOT EXISTS `zhan_discount_activity` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `name` VARCHAR(255) NOT NULL  COMMENT '活动名称',
    `discount_price` DECIMAL(10,2) NOT NULL  COMMENT '活动折扣价格',
    `status` INT NOT NULL  COMMENT '活动状态' DEFAULT 1,
    `image` VARCHAR(255)   COMMENT '活动图片',
    `description` LONGTEXT   COMMENT '活动描述',
    `activity_type` SMALLINT   COMMENT '活动类型' DEFAULT 2,
    `stock` INT NOT NULL  COMMENT '库存' DEFAULT 0,
    `start_time` DATETIME(6)   COMMENT '活动开始时间',
    `end_time` DATETIME(6)   COMMENT '活动结束时间'
) CHARACTER SET utf8mb4;
        CREATE TABLE IF NOT EXISTS `zhan_goods` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `name` VARCHAR(255) NOT NULL  COMMENT '商品名称',
    `price` DECIMAL(10,2) NOT NULL  COMMENT '商品价格',
    `status` INT NOT NULL  COMMENT '商品状态' DEFAULT 1,
    `image` VARCHAR(255)   COMMENT '商品图片',
    `description` LONGTEXT   COMMENT '商品描述',
    `category` INT   COMMENT '商品分类' DEFAULT 1,
    `stock` INT NOT NULL  COMMENT '库存' DEFAULT 0,
    `activity_id` INT COMMENT '活动',
    CONSTRAINT `fk_zhan_goo_zhan_dis_30901080` FOREIGN KEY (`activity_id`) REFERENCES `zhan_discount_activity` (`id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4;
        CREATE TABLE IF NOT EXISTS `zhan_order` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `order_sn` VARCHAR(64) NOT NULL UNIQUE,
    `completed_at` DATETIME(6),
    `status` VARCHAR(255),
    `shipping_address` JSON,
    `billing_address` JSON,
    `payment_method` SMALLINT NOT NULL  DEFAULT 1,
    `payment_status` SMALLINT   DEFAULT 1,
    `fulfillment_status` VARCHAR(255),
    `currency` SMALLINT   DEFAULT 2,
    `total_price` DECIMAL(10,2),
    `subtotal_price` DECIMAL(10,2),
    `total_tax` DECIMAL(10,2),
    `shipping_price` DECIMAL(10,2),
    `discount_price` DECIMAL(10,2),
    `customer_email` VARCHAR(255),
    `customer_phone` VARCHAR(255),
    `line_items` JSON,
    `customer_id` INT NOT NULL,
    CONSTRAINT `fk_zhan_ord_zhan_use_366559db` FOREIGN KEY (`customer_id`) REFERENCES `zhan_user` (`id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4;;"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        DROP TABLE IF EXISTS `zhan_discount_activity`;
        DROP TABLE IF EXISTS `zhan_goods`;
        DROP TABLE IF EXISTS `zhan_order`;"""
